package com.teach.hotel;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * <pre>
 * 房型价格
 * ClassName : com.teach.Type
 * Author : J.L.Zhou
 * Date : 2019年6月2日 下午4:43:17
 * Version : V1.0
 * Copyright 2019 jlzhou.top Inc. All rights reserved. 
 * 注意：本内容仅限于公司内部传阅，禁止外泄以及用于其他的商业目</pre>
 */
public class Type {
	
	public static List<Type> types = new ArrayList<>();

	private String name;
	private Integer price1;
	private Integer price2;
	private Integer price3;
	private List<Room> list = new ArrayList<Room>();
	
	
	
	
	public Type(String name, Integer price1, Integer price2, Integer price3) {
		super();
		this.name = name;
		this.price1 = price1;
		this.price2 = price2;
		this.price3 = price3;
	}
	
	
	
	
	public Type() {
		super();
	}




	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Integer getPrice1() {
		return price1;
	}
	public void setPrice1(Integer price1) {
		this.price1 = price1;
	}
	public Integer getPrice2() {
		return price2;
	}
	public void setPrice2(Integer price2) {
		this.price2 = price2;
	}
	public Integer getPrice3() {
		return price3;
	}
	public void setPrice3(Integer price3) {
		this.price3 = price3;
	}
	public List<Room> getList() {
		return list;
	}
	public void setList(List<Room> list) {
		this.list = list;
	}
	
	public static void menu(){
		System.out.println("-----------房型管理菜单----------");
		System.out.println(" 0. 返回管理菜单");
		System.out.println(" 1. 添加");
		System.out.println(" 2. 修改");
		System.out.println(" 3. 删除");
		System.out.println(" 4. 查看");
		System.out.println("-------------------------");
		Scanner in = new Scanner(System.in);
		int menu = in.nextInt();
		switch (menu) {
		case 1:
			add();
			break;
		case 2:
			update();
			break;
		case 3:
			delete();
			break;
		case 4:
			lookAll();
			break;

		default:
			SystemConsole.adminMenu();
			break;
		}
		menu();
	}
	
	public static void add(){
		Scanner in = new Scanner(System.in);
		Type type = new Type();
		System.out.println("请输入房型:");
		type.setName(in.next());
		System.out.println("请输入普通价格：");
		type.setPrice1(in.nextInt());
		System.out.println("请输入会员价格：");
		type.setPrice2(in.nextInt());
		System.out.println("请输入活动价格：");
		type.setPrice3(in.nextInt());
		types.add(type);
		
	}
	

	
	public static void update(){
		lookAll();
		Scanner in = new Scanner(System.in);
		Type type = selectType("请输入要修改类型编号:");
		System.out.println("请输入房型:");
		type.setName(in.next());
		System.out.println("请输入普通价格：");
		type.setPrice1(in.nextInt());
		System.out.println("请输入会员价格：");
		type.setPrice2(in.nextInt());
		System.out.println("请输入活动价格：");
		type.setPrice3(in.nextInt());
		
	}
	
	
	public static void delete(){
		Type t = selectType("请输入要删除类型编号:");
		types.remove(t);
	}
	
	public static void lookAll(){
		String format = "%4s%8s%8s%8s%8s\n";
		System.out.format(format, "编号","类型","普通价格","会员价格","活动价格");
		for(int i=0;i<types.size();i++){
			Type t = types.get(i);
			System.out.format(format, i,t.getName(),t.getPrice1(),t.getPrice2(),t.getPrice3());
		}
	}
	
	public static Type selectType(String msg){
		lookAll();
		Scanner in = new Scanner(System.in);
		System.out.println(msg);
		int index = in.nextInt();
		if(index>=types.size()||index<0){
			System.out.println("不存在的房型，请重新选择");
			return selectType(msg);
		}
		return types.get(index);
		
	}
	
	
}
